package com.hyj.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hyj.entity.Sections;
import com.hyj.entity.Teachers;
import com.hyj.service.SecService;
import com.hyj.service.TeaService;
import com.hyj.utils.Result;

@RestController
public class SectionsController {
	@Autowired
	private SecService SecService;
	
	@Autowired
	private TeaService teaService;
	
	@ResponseBody
	@RequestMapping("/getSec")
	public Object getSec(Sections sec) {
		List<Sections> list = SecService.getSec(sec);
		sec.setPage(null);
		sec.setLimit(null);

		System.out.println("查得到科室全部数据" + list);
		List<Sections> list2 = SecService.getSec(sec);

		return  new Result(0,"",list2.size(),list);
	}

	
	@ResponseBody
	@RequestMapping("/addSec")
	public Object addSec(Sections sec,Sections deName) {
		List<Sections> list=SecService.getSec(sec);
		
		Map<String, Object> map = new HashMap<String, Object>();
		if (null==list||list.size()==0) {
			boolean dena = SecService.addSec(sec);
			if(dena) {
				map.put("code", "0");
				map.put("msg", "添加成功！！！");
			}else {
				map.put("code", "1");
				map.put("msg", "该科室已存在，添加失败！！！");
			}
		}
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/delSec")
	public Object delSec (Integer SId) {
		
		System.out.println("拿到删除科室ID:"+SId);
		
		List<Teachers> list=teaService.getTea(null);
		
		System.out.println("拿到删除科室List:"+list);
		
		Map<String,Object> map = new HashMap<String,Object>();
		if (null==list||list.size()==0) {
			boolean Sec = SecService.delSec(SId);
			if (Sec) {
				map.put("code", "0");
				map.put("msg", "删除成功！！！");
			}else {
				map.put("code", "1");
				map.put("msg", "删除失败！！！");
				
			}
		}else {
			map.put("code", "2");
			map.put("msg", "该科室下有老师，删除失败！！");
		}
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/updateSec")
	public Object updateSec(Sections SId) {
		int de =SecService.updateSec(SId);
		System.out.println("拿到修改科室信息的数据："+SId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "科室修改");
		map.put("count", 100); 
		map.put("data", de); 
		return map;
	}
	
	
	
	
}
